﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Conventions.Inspections;
using FluentNHibernate.Mapping;
using Konekcija.Core.Reporting.Dto.Application.Configurations;

namespace Konekcija.Core.Reporting.Mappings.Configurations
{
    public class CategoryMap : ClassMap<Category>
    {
        public CategoryMap()
        {
            Schema("config");
            Table("Categories");

            Id(x => x.Id).GeneratedBy.GuidComb().Not.Nullable();
            Map(x => x.ParentCategoryId).Nullable();
            Map(x => x.Path).Nullable();
            Map(x => x.CategorySetId).Column("CategorySetId")
                .Not.Insert().Not.Update().Nullable();
            Map(x => x.Importance).Nullable();
            Map(x => x.ImageUrl).Nullable();
            Map(x => x.NumActiveContent).Nullable();
            Map(x => x.EnablePhotoUpload).Nullable();
            Map(x => x.EnableVideoUpload).Nullable();
            Map(x => x.EnableFilesUpload).Nullable();
            Map(x => x.EnableAudioUpload).Nullable();
            Map(x => x.DateCreated).Nullable();

            References(x => x.CategorySet).Nullable();

            HasMany(x => x.CategoryLanguages)
                .Inverse()
                .AsBag()
                .Key(k => k.Not.Nullable())
                .KeyColumn("CategoryId")
                .Fetch.Join()
                .Cascade.AllDeleteOrphan();

            HasManyToMany(x => x.Items)
                .LazyLoad()
                .Inverse()
                .AsBag()
                .Cascade.None()
                .ParentKeyColumn("CategoryId")
                .ChildKeyColumn("ItemId")
                .Table("content.ItemsToCategories");
        }
    }
}
